var BASE_URL = 'http://jinzhidata.com/v2'

function formatTime(timeVal, fmt) {
    timeVal = new Date(timeVal.replace(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}).*$/, '$1 $2 GMT+0000').replace(/-/g, '/'))
    var o = {
        "M+": timeVal.getMonth() + 1, //月份
        "d+": timeVal.getDate(), //日
        "h+": timeVal.getHours(), //小时
        "m+": timeVal.getMinutes(), //分
        "s+": timeVal.getSeconds(), //秒
        "q+": Math.floor((timeVal.getMonth() + 3) / 3), //季度
        "S": timeVal.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (timeVal.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}

$(function () {
    // 加载文章 todo 此处一次性加载所有的，待修改

    var queryData = {
        page: 0,
        size: 999999
    }
    $.ajax({
        url: BASE_URL + "/article/list",
        data: queryData,
        type: "get",
        contentType: 'application/json',
        dataType: "json",
        success: function (response) {
            var data = response.data
            var html = '';
            for (var i = 0; i < data.length; i++) {
                html += '<li>';
                html += '<a href="' + BASE_URL + '/article.html?articleId=' + data[i].articleId + '" >';
                html += '<h2>';
                html += '<p>' + data[i].articleTitle + '</p>';
                html += '<span>' + formatTime(data[i].createTime, "yyyy-MM-dd") + '</span>';
                html += '</h2>';
                html += '<i><img src="' + data[i].articleCover + '"></i>';
                html += "</a>";
                html += "</li>";
            }
            $(".school_sc>ul").html(html)
        }
    })
})

